namespace SampleHealthClient
{
    using System;
    using System.Net.Sockets;

    internal class Program
    {
        private static void Main()
        {
            Connect("127.0.0.1", 3000);
            Console.WriteLine("Hello World!");
        }

        private static void Connect(string server, int port)
        {
            try
            {
                // Create a TcpClient.
                // Note, for this client to work you need to have a TcpServer
                // connected to the same address as specified by the server, port
                // combination.

                var client = new TcpClient(server, port);

                var stream = client.GetStream();

                // Buffer to store the response bytes.
                var data = new byte[4];

                // String to store the response ASCII representation.


                // Read the first batch of the TcpServer response bytes.
                var bytes = stream.Read(data, 0, data.Length);
                var responseCode = BitConverter.ToInt32(data, 0);

                Console.WriteLine("Received: {0}", responseCode);

                // Close everything.
                stream.Close();
                client.Close();
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("ArgumentNullException: {0}", e);
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }

            Console.WriteLine("\n Press Enter to continue...");
            Console.Read();
        }

    }
}
